package com.zbkj.crmeb.merchant.admin.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.github.pagehelper.PageInfo;
import com.zbkj.crmeb.chant.request.AddLiveRequest;
import com.zbkj.crmeb.chant.request.AddRoomGoodsRequest;
import com.zbkj.crmeb.chant.request.AssistantRequest;
import com.zbkj.crmeb.chant.request.EditRoomRequest;
import com.zbkj.crmeb.chant.request.FeedPublicRequest;
import com.zbkj.crmeb.chant.request.OnSaleGoodsRequest;
import com.zbkj.crmeb.chant.request.RemoveAssistantRequest;
import com.zbkj.crmeb.chant.request.ReplayRequest;
import com.zbkj.crmeb.chant.request.RoomGoodsRequest;
import com.zbkj.crmeb.chant.request.RoomSubanchorRequest;
import com.zbkj.crmeb.chant.request.SortGoodsRequest;
import com.zbkj.crmeb.chant.service.ChannelLiveService;
import com.zbkj.crmeb.merchant.api.request.BroadcastGoods;
import com.zbkj.crmeb.merchant.api.request.BroadcastRoleListRequest;
import com.zbkj.crmeb.merchant.api.request.BroadcastRoleRequest;
import com.zbkj.crmeb.merchant.api.request.ResetBroadcastGoodsRequest;
import com.zbkj.crmeb.merchant.api.response.BroadcastRoleInfoResponse;
import com.zbkj.crmeb.merchant.api.response.RoomInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * <p>
 * 渠道商户直播表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-07-11
 */
@RestController
@RequestMapping("/api/admin/mer/live")
@Api(tags = "商户后台-直播")
public class MerChannelLiveController extends AdminBaseController{
    @Autowired
    private ChannelLiveService channelLiveService;

    @ApiOperation(value = "查询成员列表")
    @GetMapping(value = "/role/list")
    public CommonResult<CommonPage<BroadcastRoleInfoResponse>> getBroadcastRoleList(BroadcastRoleListRequest request, HttpServletRequest servletRequest){
        PageInfo<BroadcastRoleInfoResponse> pageInfo = channelLiveService.getBroadcastRoleList(request,getMerId(servletRequest));
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    @ApiOperation(value = "设置成员角色")
    @PostMapping(value = "/role/add")
    public CommonResult<Object> addBroadcastRole(@RequestBody @Validated BroadcastRoleRequest request, HttpServletRequest servletRequest){
        return channelLiveService.addBroadcastRole(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "解除成员角色")
    @PostMapping(value = "/role/delete")
    public CommonResult<Object> deleteBroadcastRole(@RequestBody @Validated BroadcastRoleRequest request, HttpServletRequest servletRequest){
        return channelLiveService.deleteBroadcastRole(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "获取商品列表")
    @GetMapping(value = "/goods/list")
    public CommonResult<CommonPage<BroadcastGoods>> getBroadcastGoods(@ApiParam(value = "商品状态，0：未审核。1：审核中，2：审核通过，3：审核驳回", required = true) Integer status,
                                                                      PageParamRequest pageParamRequest, HttpServletRequest servletRequest){
        PageInfo<BroadcastGoods> pageInfo = channelLiveService.getBroadcastGoods(status, pageParamRequest,getMerId(servletRequest));
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    @ApiOperation(value = "商品添加提审")
    @PostMapping(value = "/goods/add")
    public CommonResult<Object> addBroadcastGoods(@RequestBody @Validated BroadcastGoods request, HttpServletRequest servletRequest){
        return channelLiveService.addBroadcastGoods(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "更新商品")
    @PostMapping(value = "/goods/update")
    public CommonResult<Object> updateBroadcastGoods(@RequestBody @Validated BroadcastGoods request, HttpServletRequest servletRequest){
        return channelLiveService.updateBroadcastGoods(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "测回审核")
    @PostMapping(value = "/goods/reset")
    public CommonResult<Object> resetBroadcastGoods(@RequestBody @Validated ResetBroadcastGoodsRequest request, HttpServletRequest servletRequest){
        return channelLiveService.resetBroadcastGoods(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "重新提交审核")
    @GetMapping(value = "/goods/audit")
    public CommonResult<Object> auditBroadcastGoods(Integer goodsId, HttpServletRequest servletRequest){
        return channelLiveService.auditBroadcastGoods(goodsId,getMerId(servletRequest));
    }

    @ApiOperation(value = "删除商品")
    @PostMapping(value = "/goods/delete")
    public CommonResult<Object> deleteBroadcastGoods(@ApiParam(value = "商品id", required = true) Integer goodsId, HttpServletRequest servletRequest){
        return channelLiveService.deleteBroadcastGoods(goodsId,getMerId(servletRequest));
    }

    @ApiOperation(value = "直播间列表")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<RoomInfo>> getLiveList(PageParamRequest pageParamRequest, HttpServletRequest servletRequest){
        PageInfo<RoomInfo> pageInfo = channelLiveService.getLiveList(pageParamRequest,getMerId(servletRequest));
        return CommonResult.success(CommonPage.restPage(pageInfo));
    }

    @ApiOperation(value = "添加")
    @PostMapping(value = "/add")
    public CommonResult<Object> addLive(@RequestBody @Validated AddLiveRequest request, HttpServletRequest servletRequest){
        return channelLiveService.addLive(request,getMerId(servletRequest));
    }

//    @ApiOperation(value = "获取直播间回放")
//    @GetMapping(value = "/getLiveinfo/{roomId}")
//    public CommonResult<Object> getLiveInfo(@PathVariable("roomId") Integer roomId,PageParamRequest pageParamRequest, HttpServletRequest servletRequest){
//        return channelLiveService.getLiveInfo(roomId,pageParamRequest,getMerId(servletRequest));
//    }

    @ApiOperation(value = "编辑直播间")
    @PostMapping(value = "/edit")
    public CommonResult<Object> editRoom(@RequestBody @Validated EditRoomRequest request, HttpServletRequest servletRequest){
        return channelLiveService.editRoom(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "删除直播间")
    @DeleteMapping(value = "/delete/{roomId}")
    public CommonResult<Object> deleteRoom(@PathVariable("roomId") Integer roomId, HttpServletRequest servletRequest){
        return channelLiveService.deleteRoom(roomId,getMerId(servletRequest));
    }

    @ApiOperation(value = "获取直播间分享二维码")
    @GetMapping(value = "/getsharedcode")
    public CommonResult<Object> getSharedCode(@ApiParam(value = "房间id", required = true)Integer roomId,String params, HttpServletRequest servletRequest){
        return channelLiveService.getSharedCode(roomId,params,getMerId(servletRequest));
    }

    @ApiOperation(value = "查询管理直播间小助手")
    @GetMapping(value = "/getassistantlist")
    public CommonResult<Object> getAssistantList(@ApiParam(value = "房间id", required = true)Integer roomId, HttpServletRequest servletRequest){
        return channelLiveService.getAssistantList(roomId,getMerId(servletRequest));
    }

    @ApiOperation(value = "添加管理直播间小助手")
    @PostMapping(value = "/addassistant")
    public CommonResult<Object> addAssistant(@RequestBody@Validated AssistantRequest request, HttpServletRequest servletRequest){
        return channelLiveService.addAssistant(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "修改管理直播间小助手")
    @PostMapping(value = "/modifyassistant")
    public CommonResult<Object> modifyAssistant(@RequestBody@Validated AssistantRequest request, HttpServletRequest servletRequest){
        return channelLiveService.modifyAssistant(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "删除管理直播间小助手")
    @PostMapping(value = "/removeassistant")
    public CommonResult<Object> removeAssistant(@RequestBody@Validated RemoveAssistantRequest request, HttpServletRequest servletRequest){
        return channelLiveService.removeAssistant(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "开启/关闭直播间官方收录")
    @PostMapping(value = "/updatefeedpublic")
    public CommonResult<Object> updateFeedPublic(@RequestBody@Validated FeedPublicRequest request, HttpServletRequest servletRequest){
        return channelLiveService.updateFeedPublic(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "开启/关闭回放功能")
    @PostMapping(value = "/updatereplay")
    public CommonResult<Object> updateReplay(@RequestBody@Validated ReplayRequest request, HttpServletRequest servletRequest){
        return channelLiveService.updateReplay(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "开启/关闭客服功能")
    @PostMapping(value = "/updatekf")
    public CommonResult<Object> updateKf(@RequestBody@Validated ReplayRequest request, HttpServletRequest servletRequest){
        return channelLiveService.updateKf(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "开启/关闭直播间全局禁言")
    @PostMapping(value = "/updatecomment")
    public CommonResult<Object> updateComment(@RequestBody@Validated FeedPublicRequest request, HttpServletRequest servletRequest){
        return channelLiveService.updateComment(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "上下架商品")
    @PostMapping(value = "/goods/onsale")
    public CommonResult<Object> onSaleGoods(@RequestBody@Validated OnSaleGoodsRequest request, HttpServletRequest servletRequest){
        return channelLiveService.onSaleGoods(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "删除直播间商品")
    @PostMapping(value = "/goods/deleteInRoom")
    public CommonResult<Object> deleteGoodsInRoom(@RequestBody@Validated RoomGoodsRequest request, HttpServletRequest servletRequest){
        return channelLiveService.deleteGoodsInRoom(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "推送商品")
    @PostMapping(value = "/goods/push")
    public CommonResult<Object> pushGoods(@RequestBody@Validated RoomGoodsRequest request, HttpServletRequest servletRequest){
        return channelLiveService.pushGoods(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "商品排序")
    @PostMapping(value = "/goods/sort")
    public CommonResult<Object> sortGoods(@RequestBody@Validated SortGoodsRequest request, HttpServletRequest servletRequest){
        return channelLiveService.sortGoods(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "直播间导入商品")
    @PostMapping(value = "/room/addgoods")
    public CommonResult<Object> addRoomGoods(@RequestBody@Validated AddRoomGoodsRequest request, HttpServletRequest servletRequest){
        return channelLiveService.addRoomGoods(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "获取主播副号")
    @GetMapping(value = "/room/getsubanchor/{roomId}")
    public CommonResult<Object> getSubanchor(@PathVariable("roomId") Integer roomId, HttpServletRequest servletRequest){
        return channelLiveService.getSubanchor(roomId,getMerId(servletRequest));
    }

    @ApiOperation(value = "添加主播副号")
    @PostMapping(value = "/room/addsubanchor")
    public CommonResult<Object> addSubanchor(@RequestBody@Validated RoomSubanchorRequest request, HttpServletRequest servletRequest){
        return channelLiveService.addSubanchor(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "修改主播副号")
    @PostMapping(value = "/room/modifysubanchor")
    public CommonResult<Object> modifySubanchor(@RequestBody@Validated RoomSubanchorRequest request, HttpServletRequest servletRequest){
        return channelLiveService.modifySubanchor(request,getMerId(servletRequest));
    }

    @ApiOperation(value = "删除主播副号")
    @PostMapping(value = "/room/deletesubanchor/{roomId}")
    public CommonResult<Object> deleteSubanchor(@PathVariable("roomId") Integer roomId, HttpServletRequest servletRequest){
        return channelLiveService.deleteSubanchor(roomId,getMerId(servletRequest));
    }

}

